package cn.stylefeng.guns.dao.service.impl.neww;

import cn.stylefeng.guns.dao.entity.GaiaMaterialDoc;
import cn.stylefeng.guns.dao.entity.neww.PwkXs;
import cn.stylefeng.guns.dao.mapper.neww.PwkXsMapper;
import cn.stylefeng.guns.dao.service.neww.IPwkXsService;
import cn.stylefeng.guns.util.RebateDateUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author qumai
 * @since 2024-09-19
 */
@Service
@DS("yaode_sqlserver")
public class PwkXsServiceImpl extends ServiceImpl<PwkXsMapper, PwkXs> implements IPwkXsService {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

    public List<PwkXs> getBatchSaleList(String time) throws ParseException {
        QueryWrapper<PwkXs> objectQueryWrapper = Wrappers.<PwkXs>query()
                .select("批号 as MAT_BATCH,产品代码 as MAT_PRO_CODE,SUM(case when 数据类型='批发销售订单' then CAST(数量 AS decimal) else -CAST(数量 AS decimal) end) AS MAT_QTY")
                .le("日期", sdf.parse(time))
                //数据重新开始计算节点
                //todo 从11.1号开始重新计算
//                .ge("MAT_DOC_DATE", "20240601")
//                .eq("MAT_BATCH", "P20240012745")
                .in("数据类型", "批发销售订单", "批发销售退库订单号", "批发销退")
                .groupBy("批号,产品代码");


        return list(objectQueryWrapper);
    }

}
